#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi

#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc3_hyp_HF631g.info <<%EOF%
   cc3_hyp_HF631g
   --------------
   Molecule:         HF
   Thoery Level:     CC3 / 6-31G
   Test Purpose:     first hyperpolarizability for 0.1 freq. and 
                     non-totally symetric operators
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc3_hyp_HF631g.mol <<%EOF%
BASIS
6-31G
CCSD(T) unrelaxed FOP
Dum di dum di da
    2    2  X  Y  Z   1.00D-15
        9.0   1    2    1    1
F     0.0000000000000000   0.000000000   0.00000000
        1.0   1    1    1
H     0.0000000000000000   0.000000000   1.30000000
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc3_hyp_HF631g.dal <<%EOF%
**DALTON
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
.DIPVEL
.ANGMOM
**WAVE FUNCTION
.CC
*SCF INPUT
.THRESH
 1.0D-12
.NODIIS
*ORBITAL INPUT
.MOSTART
 H1DIAG
*CC INP
.NSIMLE
  1
.CC3
.RESTART
.PRINT
 2
.THRENR
1.0D-14
.THRLEQ
1.0D-14
.MXLRV
  1000
.MAX IT
  1000
*CCQR
.NOBMAT
.OPERATOR
XDIPLEN ZDIPLEN XDIPLEN
.SHGFRE
  1
 0.1 
**END OF DALTON
%EOF%
#######################################################################


#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL > cc3_hyp_HF631g.check
cat >>cc3_hyp_HF631g.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CC3 energies:
CRIT1=`$GREP "Total SCF   energy: * -99\.8705133766" $log | wc -l`
CRIT2=`$GREP "Total MP2   energy: * -99\.9862038852" $log | wc -l`
CRIT3=`$GREP "Total CC3   energy: * -99\.9894612390" $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3` 
CTRL[1]=6
ERROR[1]="ENERGIES NOT CORRECT"

# CC3 hyperpolarizability :
CRIT1=`$GREP  "XDIPLEN *\(unrel\.\) *(-|-0)\.2000 *ZDIPLEN *\(unrel\.\) *( |0)\.1000 *XDIPLEN *\(unrel\.\) *( |0)\.1000 *-1\.7420603" $log | wc -l`
TEST[2]=$CRIT1
CTRL[2]=1
ERROR[2]="CC3 HYPERPOLARIZABILITY NOT CORRECT"


PASSED=1
for i in 1 2
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%
#######################################################################
